<?php
/**
 * Short Description  
 *
 * Long Description 
 *
 * @category   
 * @package    
 * @subpackage 
 * @copyright 
 * @author     Sandeep Manne<sandeep.manne@costrategix.com>
 */

require_once "PaypalController.php";

class Paypal_IndexController extends PaypalController
{
	public function init()
	{
		
	}
	
	public function indexAction()
	{
		$paymentForm = App::getForm("paypal", "payment");
		$data = $this->getRequest()->getParams();
		
		if (!$data['INVNUM'] || !$data['AMT'] || !$data['returnUrl']) {
			throw new Exception("Unable to process checkout");
		}
		if ($this->getRequest()->isPost() && $paymentForm->isValid($data)) {
			//$data["PROFILESTARTDATE"] = da
			$response = App::getModel("paypal", "paypal")->doDirectPayment($data);
			$this->_redirect($data['returnUrl']. '/?' . $response->getBody() . 
							'&INVNUM=' . $data['INVNUM']);
		}
		$this->view->form = $paymentForm;
	}
	
	public function responseAction()
	{
		$data = $this->getRequest()->getParams();
		$this->view->data = $data;
	}
}